<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<html>
<head>
	<title>修改花店销售信息</title>
	<script type="text/javascript" src="../js/calendar/WdatePicker.js"></script>
	<script type="text/javascript" src="../js/jquery-3.5.1.min.js"></script>
	<script type="text/javascript">
		function checkValid(){
			var name=document.getElementById("name");
			if(name.value.trim()==""){
				alert("名称不能为空！");
				name.focus();
				return false;
			}

			var sdate=document.getElementById("sdate");
			if(sdate.value.trim()==""){
				alert("销售日期不能为空！");
				sdate.focus();
				return false;
			}

			reg=/^\d+(\.\d{1,2}){0,1}$/;
			var price=document.getElementById("price");

			if(!reg.test(price.value)){
				alert("价格不能为空并且只能是数字！");
				price.focus();
				return false;

			}
			var categoryid=document.getElementById("categoryid");
			if(categoryid.value==0){
				alert("请选择类别！");
				categoryid.focus();
				return false;
			}

			return true;
		}

		function checkPhoto(file) {//图片预览
			var url = null;
			if (window.createObjcectURL != undefined) {
				url = window.createOjcectURL(file);
			} else if (window.URL != undefined) {
				url = window.URL.createObjectURL(file);
			} else if (window.webkitURL != undefined) {
				url = window.webkitURL.createObjectURL(file);
			}

			var imgPhoto = document.getElementById("imgPhoto");
			imgPhoto.src = url;
		}
	</script>
</head>
<body>

<h2>修改花店销售</h2>
<a href="../index.jsp">返回首页</a><br/>
<form action="update" method="post" enctype="multipart/form-data">
	<table>
		<tr>
			<td>销售编号</td>
			<td>
				<input type="text" id="id" name="id" readonly="readonly" value="${t.id}" />
				<span id="divId" style="color: red;">${error}</span>
			</td>
		</tr>
		<tr>
			<td>名称</td>
			<td><input type="text" id="name" name="name" value="${t.name}" /></td>
		</tr>
		<tr>
			<td>是否收到</td>
			<td>
				<input type="radio" name="isreceived" value="true" ${t.isreceived?"checked='checked'":""} />是
				<input type="radio" name="isreceived" value="false" ${!t.isreceived?"checked='checked'":""} />否
			</td>
		</tr>
		<tr>
			<td>销售日期</td>
			<td>
				<input type="text" Class="Wdate" id="sdate" name="sdate"
					   onclick="WdatePicker();" value="${t.sdate}" />
			</td>
		</tr>
		<tr>
			<td>价格</td>
			<td>
				<input type="text" id="price" name="price" value="${t.price}" />
			</td>
		</tr>
		<tr>
			<td>照片</td>
			<td>
				<input type="file" name="photo" id="photo" onchange="checkPhoto(this.files[0])" />
				<img src="${pageContext.request.contextPath }/files/${t.photo}" width="120px" height="180px" name="imgPhoto" id="imgPhoto" />
			</td>
		</tr>
		<tr>
			<td>类别</td>
			<td>
				<select id="categoryid" name="categoryid">

				</select>
			</td>
		</tr>
		<tr>
			<td colspan="2" style="text-align: center;">
				<input type="submit" name="btnSubmit" value="修改花店销售" onclick="return checkValid()" />
			</td>
		</tr>
	</table>
</form>
</body>
<script type="text/javascript">
	function initList(pageIndex){
		// alert("hi");
		// $.json()方法
		$.getJSON("${pageContext.request.contextPath }/sys/listprovince",null,processList);
	}

	function processList(data) {
		// alert(data);
		$("#categoryid").empty();
		$("#categoryid").append("<option value='0'>请选择...</option>");
		$(data).each(function () {
			var optionValue = "<option value='" + this.id + "'>" + this.name + "</option>"
			$("#categoryid").append(optionValue);
			// alert(strInfo);
		});

		$("#categoryid").val(${t.categoryid});
	}

	$(document).ready(function () {
		initList();
	});
</script>
</html>
